# Author：liyimei
# Time：2023/5/15 18:41
import os

from selenium import webdriver
import time

# 实例化配置对象
from selenium.webdriver.common.by import By

options = webdriver.ChromeOptions()
# 添加参数配置
options.add_argument(r'--user-data-dir=C:\Users\25387\AppData\Local\Google\Chrome\User Data')
# 浏览器加载配置项
driver = webdriver.Chrome(options=options)
# 访问页面
driver.get('https://mail.163.com')
# 1.点击写信输入信息
driver.find_element(By.ID, '_mail_component_78_78').click()
# 2.定位收件人输入框输入内容
driver.find_element(By.CLASS_NAME, 'nui-editableAddr-ipt').send_keys('18571687653@163.com')
# 3.定位主题输入框输入内存
time.sleep(2)
driver.find_element(By.XPATH, "//input[contains(@id,'subjectInput')]").send_keys('我是燕子')
time.sleep(2)
# 根据上传文件路径,定位上传按钮上传文件
file = os.path.abspath("hello.py")
print(file)
driver.find_element(By.CLASS_NAME, 'O0').send_keys(file)

# 定位文本输入框输入文本内容
frame1 = driver.find_element(By.CLASS_NAME, 'APP-editor-iframe')
driver.switch_to.frame(frame1)
driver.find_element(By.TAG_NAME, 'body').send_keys('好的')

driver.switch_to.default_content()
driver.find_element(By.XPATH, '//footer/div/span[2]').click()

time.sleep(5)
driver.quit()
